import Mysql from '../../core/Mysql'
import { Models } from '../../common/typings/model'
interface UserId {
  email?: string
  id?: string | number
  openId?: string
}

class UserManager {
  public static async getUser({ email, id, openId }: UserId): Promise<Models.User | boolean> {
    let where = ''
    if (email) {
      where = `user.email = '${email}'`
    } else if (id) {
      where = `user.id = '${id}'`
    } else if (openId) {
      where = `user.open_id = '${openId}'`
    } else {
      throw new Error('缺少辨识用户的email、id、openId')
    }
    const user: Models.Result = await Mysql.command(`
            SELECT
            id,user_name,email,test,info,password,level
            FROM
                user
            where
                ${where}
        `)
    if (user.results.length < 1) {
      return false
    }
    return user.results[0]
  }

  public static async register() {}
}

export default UserManager
